<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function Aniaml(name, age) {
            this.name = name
            this.age = age
        }
        Aniaml.prototype.sayhi = function() {
            console.log('bbbbbbbbb');
        }

        // function Person(gender, ...arg) {
        //     this.gender = gender
        //         // 实现继承
        //     Aniaml.apply(this, arg)
        // }

        function Person(gender, name, age) {
            this.gender = gender
                // 实现继承
            Aniaml.call(this, name, age)
        }



        Person.prototype.play = function() {
            console.log('aaaaaaaaaaa');
        }
        const p = new Person('nv', 'xz', 28)
        console.log(p);

        // 普通函数调用 this指向window
        Aniaml('鳖', 999)
        console.log(window.name, window.age);

        const obj = {
            msg: 'ssssssssssss'
        }

        // 在调用Aniaml的时候 使用call方法 把Aniaml内部的this改成了obj，所以会加
        Aniaml.call(obj, 'xh', 18);
        console.log(obj);
    </script>
</body>

</html>